package bugstack.proxy.cglib;

import bugstack.proxy.cglib.service.UserService;
import bugstack.proxy.cglib.service.impl.UserServiceImpl;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

/**
 * @author caojie
 * @version 1.0
 * @Description
 * @date 2023/7/31 14:25
 */
public class CglibProxy implements MethodInterceptor {

    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("我被cglib代理了");
        return methodProxy.invokeSuper(o,objects);
    }
    @Test
    public void test1(){
        UserService userService = (UserService) Enhancer.create(UserServiceImpl.class, this);
        userService.get(1);
    }
}

